package com.jqq.set_;


import java.util.HashSet;

/**
 * @author 姬倩倩
 * @version 1.0
 */
public class HashSet_ {
    @SuppressWarnings({"all"})
    public static void main(String[] args) {
        HashSet set = new HashSet();
        /*
        public HashSet() {
            map = new HashMap<>();
        }
         */
        //add方法返回boolean值
        System.out.println(set.add("john"));
        System.out.println(set.add("lucy"));//true
        System.out.println(set.add("john"));//false
        System.out.println(set.add("jack"));
        System.out.println(set.add("rose"));
        set.remove("john");
        System.out.println("set="+set);

        //两个不同的狗对象不算重复元素，因为所指向的不是同一片地址
        set.add(new Dog("tom"));
        set.add(new Dog("tom"));
        System.out.println("set="+set);

        //非常经典的面试题
        set.add(new String("jqq"));
        System.out.println(set.add("jqq"));//false
        System.out.println(set.add(new String("jqq")));//false
        System.out.println("set="+set);
    }
}
class Dog{
    public String name;

    public Dog(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                '}';
    }
}